byte_array

An array of bytes. This type is immutable.

Since

0.6.0

Constructors

Link copied to clipboard
pure constructor(hex: text)

Construct a byte array from a hexadecimal string.

pure constructor(list: list<integer>)

Construct a byte_array from a list of integers.

Functions

Link copied to clipboard
pure function decode(): text
Link copied to clipboard
pure function empty(): boolean

Returns true if this byte_array is empty, false otherwise.

x.empty() is equivalent to x.size() == 0.

Link copied to clipboard
static function from_base64(value: text): byte_array

Create a byte array from a base-64 string.

Valid base-64 strings may include the characters a-z, A-Z, 0-9, + and / as significant characters, and '=' as padding.

Link copied to clipboard
pure static function from_hex(value: text): byte_array

Create a byte array from a hexadecimal string.

The given hexadecimal string must have even length, since two hexadecimal characters encode one byte.

Link copied to clipboard
pure static function from_list(list: list<integer>): byte_array

Create a byte_array from a list of integers.

The inverse of byte_array.to_list().

All integers in the passed list are treated as single-byte values, i.e. they must be in the range 0 <= x < 256, and therefore the returned byte_array will be equal in size to the passed list.

Link copied to clipboard
pure function join_to_text([separator: text], [prefix: text], [postfix: text], [limit: integer?], [truncated: text], [transform: (integer) -> text]): text

Generate a textual representation of this iterable.

An optional separator, prefix and postfix can be provided. One can also provide a limit: integer?. If there are more elements in the result than limit, the elements whose indices exceed limit are omitted, and the passed truncated: text is included instead.

Examples:

  • [1, 2, 3].join_to_text() returns '1, 2, 3'.

  • [1, 2, 3].join_to_text('_') returns '1_2_3'.

  • [1, 2, 3].join_to_text('*', '(', ')') returns '(1*2*3)'.

  • list<T>().join_to_text('!', '(', ')') returns '()' (where T is a valid type).

  • range(10).join_to_text('', '', '', 5) returns '01234...'.

  • range(10).join_to_text('', '', '', 5, 'more') returns '01234more'.

Where the function even is defined:

function even(x: integer): text {
return if (x % 2 == 0) 'EVEN' else 'ODD';
}

Then:

  • range(10).join_to_text('->', '{', '}', 5, '...', even(*)) returns {EVEN->ODD->EVEN->ODD->EVEN->...}.

Link copied to clipboard
(alias) pure function len(): integer

Returns the number of bytes in this byte_array.

Alias
Link copied to clipboard
pure function repeat(n: integer): byte_array

Repeats this byte_array n times.

Examples:

  • x'1234abcd'.repeat(3) returns x'1234abcd1234abcd1234abcd'

  • x''.repeat(3) returns x''

  • x'1234abcd'.repeat(0) returns x''

Link copied to clipboard
pure function reversed(): byte_array

Returns a reversed copy of this byte_array.

Link copied to clipboard
pure function sha256(): byte_array

Calculates the SHA-256 digest (hash) of this byte array.

Link copied to clipboard
pure function size(): integer

Returns the number of bytes in this byte_array.

Link copied to clipboard
pure function sub(start: integer): byte_array

Returns a sub-array of this byte array starting from the specified index (inclusive).

pure function sub(start: integer, end: integer): byte_array

Returns a sub-array of this byte array from the specified start index (inclusive) to the specified end index (exclusive).

Link copied to clipboard
pure function to_base64(): text

Returns a base-64 text representation of this byte_array.

Inverse of byte_array.from_base64(text).

Link copied to clipboard
pure function to_hex(): text

Returns a hexadecimal text representation of this byte_array.

Inverse of byte_array.from_hex(text).

Link copied to clipboard
pure function to_list(): list<integer>

Converts this byte_array to a list of integers.

The inverse of byte_array.from_list(list<integer>).

Each byte in the array is converted to a single integer 0 <= x < 256 in the returned list.

Link copied to clipboard
(alias) pure function toList(): list<integer>

Converts this byte_array to a list of integers.

The inverse of byte_array.from_list(list<integer>).

Each byte in the array is converted to a single integer 0 <= x < 256 in the returned list.

Alias